package com.sparrow.common.ai.fsm;

import java.util.HashMap;
import java.util.Map;

public class StateMachineContext<E> {
    private final E owner;
    private final StateMachine<E> stateMachine;
    private final Map<String, Object> data = new HashMap<>();

    public StateMachineContext(E owner, StateMachine<E> stateMachine) {
        this.owner = owner;
        this.stateMachine = stateMachine;
    }

    public E getOwner() {
        return owner;
    }

    public StateMachine<E> getStateMachine() {
        return stateMachine;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void put(String key, Object value) {
        data.put(key, value);
    }

    public Object get(String key) {
        return data.get(key);
    }

    public <T> T get(String key, Class<T> clazz) {
        Object value = data.get(key);
        if (clazz.isInstance(value)) {
            return clazz.cast(value);
        }
        return null;
    }

    public boolean has(String key) {
        return data.containsKey(key);
    }

    public boolean remove(String key) {
        return data.remove(key) != null;
    }
}



